package com.ebelter.seneo.ui.fragments.infos;


import android.graphics.Color;
import android.os.Bundle;
import android.widget.TextView;

import com.ebelter.btcomlib.common.IOrder;
import com.ebelter.btcomlib.models.db.products.seneo.SeneoUserCurrentMeasureRecord;
import com.ebelter.btcomlib.models.db.products.seneo.SeneoUserinfos;
import com.ebelter.btcomlib.utils.StringUtils;
import com.ebelter.btcomlib.utils.ViewUtils;
import com.ebelter.seneo.R;
import com.ebelter.seneo.contants.IUserContant;
import com.ebelter.seneo.ui.fragments.BaseFragment;
import com.ebelter.seneo.ui.fragments.main.Info_Fragment;
import com.ebelter.seneo.ui.views.LevelView;
import com.ebelter.seneo.utils.SeneoUtils;


//填写密码
public class Info_Bodyfatpercentage_Fragment extends BaseFragment  implements Info_Fragment.IInfoUpdateInterface {

    public static final String TAG = "Info_Bodyfatpercentage_Fragment";
    TextView infofly_value_tv;
    TextView infofly_valueunit_tv;
    TextView infofly_tip1_tv;
    LevelView info_levelview;

    @Override
    protected int setLayoutResouceId() {
        return R.layout.info_fly1;
    }

    @Override
    protected void initView() {
        FV();
    }

    private void FV() {
        infofly_value_tv=findViewById(R.id.infofly_value_tv);
        infofly_valueunit_tv=findViewById(R.id.infofly_valueunit_tv);
        infofly_tip1_tv=findViewById(R.id.infofly_tip1_tv);
        info_levelview=findViewById(R.id.info_levelview);

         ViewUtils.setTextViewStr(infofly_valueunit_tv,"%");
    }


    @Override
    protected void initData(Bundle arguments) {

        String tip=getString(R.string.str_Body_fat_percentage_introduce);
        infofly_tip1_tv.setText(tip);

        //执行了这一句 下面的UpdateCurrentMesureInfo接口会回调display方法
        if (getParentFragment()!=null){
            ((Info_Fragment)getParentFragment()).getCurrentDisplayInfo(TAG);
        }
    }



    @Override
    public void UpdateCurrentMesureInfo(SeneoUserinfos currentUserinfos, SeneoUserCurrentMeasureRecord currentMeasureRecord) {
        displayFat(currentUserinfos,currentMeasureRecord);
    }


    float[] middle = new float[]{18.5f,24.0f,28.0f};
    final int[] colors = new int[]{
            Color.parseColor("#54BF4B"),
            Color.parseColor("#49D8F1"),
            Color.parseColor("#EFB847"),
            Color.parseColor("#EE7D65"),
    };
    String[] buttoms = new String[]{
            StringUtils.getResStr(R.string.piandi),
            StringUtils.getResStr(R.string.biaozhun),
            StringUtils.getResStr(R.string.pianpang),
            StringUtils.getResStr(R.string.feipang)};

    private void displayFat(SeneoUserinfos currentUserinfos,SeneoUserCurrentMeasureRecord currentMeasureRecord) {
        if (info_levelview==null||currentUserinfos==null)return;


        initMiddleValue(currentUserinfos);//初始化middle值 因为middle值受性别年龄的影响

        info_levelview.setDisInfo(middle,colors,buttoms);
        info_levelview.setMinMaxValuse(0,60);
        if (currentMeasureRecord!=null){
            if (currentMeasureRecord.fat!=0){
                info_levelview.setDrawWujiaoxin((true));
                ViewUtils.setTextViewStr(infofly_value_tv,currentMeasureRecord.fat+"");
            }else if (currentMeasureRecord.fat == 0){
                info_levelview.setDrawWujiaoxin((false));
                ViewUtils.setTextViewStr(infofly_value_tv, IUserContant.IDIS.Non);
            }
            info_levelview.displayValue(currentMeasureRecord.fat);
        }else {
            info_levelview.setDrawWujiaoxin((false));
            info_levelview.displayValue(0);
            ViewUtils.setTextViewStr(infofly_value_tv, IUserContant.IDIS.Non);
        }



    }

    //初始化moddle值
    private void initMiddleValue(SeneoUserinfos currentUserinfos) {

        int year = SeneoUtils.getBirthdayIntValue(currentUserinfos.birthday,0,1991);
        int age = SeneoUtils.getAgeByBirthday(year);

        if (currentUserinfos.sex==0){//男
            if (age<=39){
                middle[0]=10;
                middle[1]=21;
                middle[2]=26;
            }else if (age>39&&age<=59){
                middle[0]=11;
                middle[1]=22;
                middle[2]=27;
            }else {
                middle[0]=13;
                middle[1]=24;
                middle[2]=29;
            }

        }else {//女
            if (age<=39){
                middle[0]=20;
                middle[1]=34;
                middle[2]=39;
            }else if (age>39&&age<=59){
                middle[0]=21;
                middle[1]=35;
                middle[2]=40;
            }else {
                middle[0]=22;
                middle[1]=36;
                middle[2]=41;
            }
        }



    }
}
